package com.caigou.modules.gallery.ui.comment

import android.text.TextUtils
import android.util.TypedValue
import android.widget.ImageView
import androidx.activity.viewModels
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.caigou.comm.base.bean.AppBackgroundInfo
import com.caigou.comm.base.bus.BusKey
import com.caigou.comm.base.bus.LiveDataBus
import com.caigou.comm.base.constants.AppConstants
import com.caigou.comm.base.constants.RouterPath
import com.caigou.comm.base.container.BaseReplyActivity
import com.caigou.comm.base.ext.*
import com.caigou.comm.base.utils.GlideEngine
import com.caigou.modules.gallery.R
import com.caigou.modules.gallery.viewmodel.CommentViewModel
import com.luck.picture.lib.PictureSelector
import com.luck.picture.lib.config.PictureConfig
import com.luck.picture.lib.config.PictureMimeType
import com.luck.picture.lib.entity.LocalMedia
import com.luck.picture.lib.listener.OnResultCallbackListener
import com.lwkandroid.widget.ngv.DefaultNgvAdapter
import com.lwkandroid.widget.ngv.NgvChildImageView
import dagger.hilt.android.AndroidEntryPoint
import java.io.File

/**
 * @author #Suyghur.
 * Created on 2021/12/03
 */
@Route(path = RouterPath.Gallery.PAGE_REPLY)
@AndroidEntryPoint
class GalleryReplyActivity : BaseReplyActivity() {

    private val commentViewModel: CommentViewModel by viewModels()

    @JvmField
    @Autowired(name = AppConstants.DEPOT_ID)
    var depotId = 0

    @JvmField
    @Autowired(name = AppConstants.DETAIL_ID)
    var detailId = 1

    @JvmField
    @Autowired(name = AppConstants.RECEIVER_ID)
    var receiverId = ""

    @JvmField
    @Autowired(name = AppConstants.DATA_TYPE)
    var type = 0

    override fun initView() {
        super.initView()

        binding.replyBtnSubmit.setOnClickListener {
            val content = binding.replyEtContent.text.toString()
            val files: MutableList<File> = mutableListOf()
            urls.forEach {
                files.add(File(it))
            }
            commentViewModel.setReply(content, files, AppBackgroundInfo.instance.userBean!!.userId, receiverId, depotId, detailId, type)
        }
    }

    override fun observeViewModel() {
        observe(commentViewModel.replyLiveData, ::handleSetReply)
    }
}